import $ from 'jquery';
export default {
	productPrice(self) {
		self.httptool.ajaxPost(self.apis.priceTrend, self.searchCondition, res => {
			console.log(res)
			let data = res.data;			
			self.xAxis = [];
			self.yAxis = [];
			if(data.list && data.list.length > 0){
				for(let item of data.list){
					self.xAxis.push(item.priceDate.split(' ')[0]);
					self.yAxis.push(item.price);
				}
			}
			self.lowest = data.min;
			setTimeout(() => {
				self.drawLine();
			}, 10)
		})
	},
	getExchangeRate(self){
		self.httptool.ajaxPost(self.apis.getExchangeRate, null, res => {
			console.log(res)
			let data = res.data;
			self.exchangeRate = data;
			console.log(self.exchangeRate)
		})
	},
	latestPrice(self,name){
		let params = {
			name:name  // （必传）（字符串）取值范围：crude（原油） | lng（LNG） | fuel（燃料油） | naphtha（石脑油）
		}
		self.httptool.ajaxPost(self.apis.latestPrice,params,res=>{
			let data = res.data;
			self.list = data.list;
		})		
	},
	areaPriceRecordAPI(self){
		self.httptool.ajaxPost(self.apis.areaPriceRecordAPI,null,res=>{
			let data = res.data;
			self.areaPriceRecord = data;
		})
	},
	priceTrend(self){
		self.httptool.ajaxPost(self.apis.priceTrend,self.searchCondition,res=>{
			let data = res.data.list;
			self.trendList = data;
		})
	},
	cityList(self){
		self.cityList = {};
		self.httptool.ajaxPost(self.apis.cityList,null,res=>{
			let data = res.data.list;
			setTimeout(()=>{
				self.closeLoading();
			},0)
			for(let item of data){
				if(self.cityList[item.areaName]){
					self.cityList[item.areaName].push(item.city)
				}else{
					self.cityList[item.areaName] = [item.city]
				}
			}
			self.$store.commit('changeValue',{
				name:'cityList',
				value: self.cityList
			})
		},function(res){
			self.closeLoading();
		});
	}
	
}